<html>
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<style type="text/css">
body {
	font-family: Tahoma;
	font-size: 100%;
	background-color: #75848B;
}
img {
	vertical-align: middle;
}
.plurk {
	/*border: 1px solid #ccc;*/
	padding: 5px;
	margin: 5px;
	background-color: #FFFFFF;
}
.qualifier {
	background-color: #006699;
	padding-top: 0pt;
	padding-right: 3px;
	padding-bottom: 0pt;
	padding-left: 3px;
	color: white;
	margin-top: 0pt;
	margin-right: 3px;
	margin-bottom: 0pt;
	margin-left: 4px;	
}
</style>
</head>
<body>
<?php
include('PlurkAPI.php');

$username	= $_REQUEST['username'];
$password	= $_REQUEST['password'];
$api_key	= 'yYsxraBDrokpOvfDSkQT8hc0ySHxKxIx'; // Get Plurk API Key = http://www.plurk.com/API#key
$MyPlurk	= new PlurkAPI();
$MyPlurk->InitPlurk($api_key);

if($_REQUEST['submit']) {
	$MyPlurk->LoginPlurk($username, $password);

	// Post Plurk
	// $MyPlurk->PostPlurk('Hello World!');

	$data = $MyPlurk->GetOwnProfile();	
	$avatar = $MyPlurk->GetAvatar($data['user_info']['uid'], $data['user_info']['avatar'], 'big');
	print "<img src='".$avatar."' />";
	print "<br />";
	print "Welcome, <strong>".$data['user_info']['full_name']."</strong> <a href='example.php'>(logout)</a><br />";
	print "Your Friends: ".$data['friends_count']."<br />";
	print "Your Fans: ".$data['fans_count']."<br />";
?>
<!--<form name="form1" method="post" action="">
  <label>Status
  <textarea name="status" id="status" cols="45" rows="5"></textarea>
  </label>
</form>-->

<?php
	$data = $MyPlurk->GetPlurks();
	foreach ($data['plurks'] as $plurk) {
		$owner_id = $plurk['owner_id'];
		$avatar = $MyPlurk->GetAvatar($owner_id, $data['plurk_users'][$owner_id]['avatar']);
		$display_name = $data['plurk_users'][$owner_id]['display_name'];
		if($plurk['qualifier_translated'] != '') {
			$qualifier = $plurk['qualifier_translated'];
		} else {
			$qualifier = $plurk['qualifier'];
		}
		$content = '<span class="qualifier">'.$qualifier.'</span>'.$plurk['content'];
		$responses = $plurk['response_count'];
		$plurkID = $plurk['plurk_id'];
		print "<div class='plurk'><img src='".$avatar."' /> <strong>".$display_name."</strong>".$content." <a href='?plurkID=".$plurkID."'>(".$responses." respon)</a></div>";
	}
	
} else if($_REQUEST['plurkID'] <> 0) {
	$data = $MyPlurk->GetPlurk($_REQUEST['plurkID']);
	print "<div class='plurk'><img src='".$MyPlurk->GetAvatar($data['user']['id'], $data['user']['avatar'])."' /> <strong>".$data['user']['display_name']."</strong>: ".$data['plurk']['content']."</div>";	
	
	$data = $MyPlurk->GetResponses($_REQUEST['plurkID']);
	foreach ($data['responses'] as $response) {
		$user_id = $response['user_id'];
		$avatar = $MyPlurk->GetAvatar($user_id, $data['friends'][$user_id]['avatar']);
		$display_name = $data['friends'][$user_id]['display_name'];
		if($response['qualifier_translated'] != '') {
			$qualifier = $response['qualifier_translated'];
		} else {
			$qualifier = $response['qualifier'];
		}		
		$content = '<span class="qualifier">'.$qualifier.'</span>'.$response['content'];
		print "<div class='plurk'><img src='".$avatar."' /> <strong>".$display_name."</strong>".$content."</div>";
	}	
} else {
?>


<h1>Plurk API Test</h1>
<form method="post">
  <label>
  Username:
  <input type="text" name="username" id="username" />
  </label>
  <label>Password:
  <input type="password" name="password" id="password" />
  </label>  
  <input type="submit" name="submit" id="button" value="Submit" />
</form>
<?php } ?>
</body>
</html>